/**
 * Created by Administrator on 2017/8/23.
 */


$(function () {
    changeBackgroudColor();
    setInterval(function(){
        changeBackgroudColor();
    },50000000);
});

    function changeBackgroudColor(){
        $.ajax({
            type: "POST",
            url: "mechanics/queryAllColor",
            timeout: 5000,
            dataType: "json",
            cache: false,
            success: function (data) {
                console.info(data.items[0])
                for(var i=0;i<data.length;i++){
                    if($("#"+data.items[i].devicePosition).length>0){       //判断该元素是否存在
                        if(data.items[i].deviceState=="1"){

                            $("#"+data.items[i].devicePosition).css("background-color","#F0F708");//改变元素背景颜色

                        }
                        else if(data.items[i].deviceState=="2"){
                            $("#"+data.items[i].devicePosition).css("background-color","#3EF907");//改变元素背景颜色

                        }
                        else if(data.items[i].deviceState=="3"){
                            $("#"+data.items[i].devicePosition).css("background-color","#F90707");//改变元素背景颜色

                        }else{
                            $("#"+data.items[i].devicePosition).css("background-color","#C16088");//改变元素背景颜色

                        }
                    }else{
                        // alert("需要添加"+data.items[i].deviceName);
                    }
                }

            },
            error: function () {
                $.messager.alert("提示", "出现了不可预知的错误，请重新操作！");
            }
        })
}

